package com.example.demo.controller;

import com.example.demo.dto.UserDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@RestController // This means that this class is a Controller
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
public class MainController {
  Logger logger = LoggerFactory.getLogger(getClass());

  @PostMapping(path="/add") // Map ONLY POST Requests
  public @ResponseBody String addNewUser (
      @RequestParam String name
      , @RequestParam String email
      , @RequestParam String password
      ) {
    // @ResponseBody means the returned String is the response, not a view name
    // @RequestParam means it is a parameter from the GET or POST request

    return "Saved";
  }

  @GetMapping(path="/all")
  public @ResponseBody Iterable<UserDto> getAllUsers() {
  return null;
  }

  @GetMapping(path="/all2")
  public @ResponseBody Iterable<UserDto> getAllUsers2(
    @RequestParam(defaultValue = "0") int page,
    @RequestParam(defaultValue = "10") int pageSize
  ) {
    logger.error("sdfsdf");
    Pageable paging = PageRequest.of(page, pageSize);
    return null;
  }
}